package main;

import commons.utils.Utils;
import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

// Sert à calculer la taille d'un pixel (en mètre), données à renseigner dans le fichier INI
//  et utilisé par AutoGene pour afficher les objets à la bonne taille selon l'échelle
public class FrameCalibrationDisplay extends javax.swing.JFrame {

    public FrameCalibrationDisplay() {
        initComponents();

		MyPanel p = new MyPanel();
		this.jPanel1.add(p, java.awt.BorderLayout.CENTER);
    }


	class MyPanel extends JPanel {

		@Override
		protected void paintComponent(Graphics g) {
			super.paintComponent(g);
			g.drawRect(0, 0, 500, 500);
		}
	}




    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tf_TailleCoteRect = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tf_TaillePixel = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        btn_Calcule = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Lg. coté du carré (cm) :");

        jLabel2.setText("valeur à indiquer dans fichier INI (TAILLE_PIXEL) :");

        tf_TaillePixel.setEditable(false);

        jPanel1.setLayout(new java.awt.BorderLayout());

        btn_Calcule.setText("=> Calcule =>");
        btn_Calcule.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CalculeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 776, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_TailleCoteRect, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(37, 37, 37)
                        .addComponent(btn_Calcule)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_TaillePixel, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tf_TailleCoteRect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_Calcule)
                    .addComponent(tf_TaillePixel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 655, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void btn_CalculeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CalculeActionPerformed
		tf_TaillePixel.setText("");
		String sCoteRect = tf_TailleCoteRect.getText();
		if (Utils.isFloat(sCoteRect)) {
			double taillePixel = (Double.parseDouble(sCoteRect)/100)/500;
			tf_TaillePixel.setText(String.format("%f", taillePixel));
		} else {
			JOptionPane.showMessageDialog(this, "La longueur entrée est invalide");
		}
	}//GEN-LAST:event_btn_CalculeActionPerformed


    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrameCalibrationDisplay().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Calcule;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField tf_TailleCoteRect;
    private javax.swing.JTextField tf_TaillePixel;
    // End of variables declaration//GEN-END:variables

}
